﻿using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using EpiNEXT.Core.Validation;

namespace EpiNEXT.Core.Collections
{
    [Serializable()]
    public class ConditionCollection : ObservableCollection<ConditionBase>
    {
        private string _logicalOperatorString = "OR";
        private LogicalOperators _logicalOperator = LogicalOperators.OR;

        [XmlIgnore]
        public LogicalOperators LogicalOperator
        {
            get { return this._logicalOperator; }
            set
            {
                if (LogicalOperator != value)
                {
                    this._logicalOperator = value;
                    switch (LogicalOperator)
                    {
                        case LogicalOperators.AND:
                            LogicalOperatorString = "AND";
                            break;
                        case LogicalOperators.OR:
                            LogicalOperatorString = "OR";
                            break;
                        case LogicalOperators.XOR:
                            LogicalOperatorString = "XOR";
                            break;
                    }
                }
            }
        }

        [XmlAttribute("Join")]
        public string LogicalOperatorString
        {
            get { return this._logicalOperatorString; }
            set
            {
                if (!LogicalOperatorString.Equals(value))
                {
                    this._logicalOperatorString = value;
                    switch (LogicalOperatorString)
                    {
                        case "AND":
                            LogicalOperator = LogicalOperators.AND;
                            break;
                        case "OR":
                            LogicalOperator = LogicalOperators.OR;
                            break;
                        case "XOR":
                            LogicalOperator = LogicalOperators.XOR;
                            break;
                    }
                }
            }
        }

        public ConditionCollection()
            : base()
        {
            LogicalOperator = LogicalOperators.OR;
        }
    }
}
